package com.spring.mybatis.anno.service.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.spring.mybatis.anno.dao.CarDao;
import com.spring.mybatis.anno.po.Car;
import com.spring.mybatis.anno.service.CarService;

@Service("carService")
@Transactional(rollbackFor = Throwable.class)
public class CarServiceImpl implements CarService {

  @Autowired
  private CarDao carDao;


  @Override
  @Transactional(readOnly = true)
  public Car selectById(String id) {
    return carDao.selectById(id);
  }

  @Override
  @Transactional(readOnly = true)
  public Car selectByCarName(String username) {
    return carDao.selectBycarName(username);
  }

  @Override
  @Transactional(readOnly = true)
  public List<Car> selectAll() {
    return carDao.selectAll();
  }

  @Override
  public Long insert(Car car) {
    carDao.insert(car);
    return car.getId();
  }

  @Override
  public boolean update(Car car) {
    return carDao.update(car) == 1;
  }

  @Override
  public boolean delete(Long id) {
    return carDao.deleteById(id) == 1;
  }

}
